<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>货物类别</title>
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/themes/black/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/themes/color.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
</head>
<script type="text/javascript">
//显示增加
function newGoodType(){
	$("#addGoodType").window('open'); 
}
//增加框取消清除
function clearForm() {
	$("#ff").form('clear');
}
//增加数据
function addGoodType() {
	$("#ff").form('submit', {
		url:"${pageContext.request.contextPath}/show/add_addGoodType.do",
		success : function(data) {
			$.messager.alert('提示','添加成功','info',function(){
	    	$("#goodtype").datagrid('reload');
	    	$("#addGoodType").window("close");
	    	});  	  
	}
	});
}
/**
 * 删除信息
 */
function delGoodType(){
	var rows = $('#goodtype').datagrid('getSelections');
	var ids = new Array();
	for (var i = 0; i < rows.length; i++) {
		ids[i] = rows[i].id;
	}
	if (rows) {
		$.messager.confirm('提示', '确认删除'+rows.length+'条信息', function(r) {
			if (r) {
				$.post('${pageContext.request.contextPath}/show/del_delGoodType.do', {
					'ids' : ids
				}, function(result) {
					$('#goodtype').datagrid('reload'); // 重新加载数据
				});
			}
		});
	}
}
/**
 * 修改货物类别信息
 */
 function editGoodType(){
	 var data = $('#goodtype').datagrid('getSelections');
		for (var i = 0; i < data.length; i++) {
			$("#id").textbox('setValue',data[i].id);
			$("#name").textbox('setValue',data[i].name);
			$("#remark").textbox('setValue',data[i].remark);
		}
		if(data.length==1){
		$('#updateGoodType').window('open');
		}
		else{
			alert("请选择一条数据");
		}
}
//修改数据
 function updateGoodType(){
 	var rows = $('#goodtype').datagrid('getSelected');
 	var id=$("#id").textbox('setValue',rows.id);
 	if(rows){
 		$("#fm").form('submit', {
 			url:"${pageContext.request.contextPath}/show/update_updateGoodType.do?id"+id,
 			success : function(data) {
 				$.messager.alert('提示','修改成功','info',function() {
 					$("#goodtype").datagrid('reload');
 			    	$("#updateGoodType").window("close");
 			    	});
 		}
 		});
 	}
 } 
</script>
<body>
<table id="goodtype" title="货物类别信息" class="easyui-datagrid"
		style="width: 100%"
		url="${pageContext.request.contextPath}/show/find_showGoodType.do"
		toolbar="#toolbar" fit="true"
		pagination="true" rownumbers="true" fitColumns="true">

		<thead>
			<tr>
				<th field="check" checkbox=true width="50px"></th>
				<th data-options="field:'id',width:100,hidden:'true'" >货物id</th>
				<th data-options="field:'name',width:100">货物类别</th>
				<th data-options="field:'remark',width:100">备注</th>
			</tr>
		</thead>
	</table>
	<div id="toolbar">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-add" plain="true" onclick="newGoodType()">增加货物类别</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-edit" plain="true" onclick="editGoodType()">修改货物类别</a> <a
			href="javascript:void(0)" class="easyui-linkbutton"
			iconCls="icon-remove" plain="true" onclick="delGoodType()">删除货物类别</a>
	</div>
 <!-- 增加数据显示框 -->
    <div class="easyui-window" closed="true" id="addGoodType" title="信息增加"
		 data-options="modal:true">
		<form id="ff" method="post" style="text-align: center">
			<p>
				货物名称:<input name="name" id="gname" class="f1 easyui-textbox"	
					data-options="required:true,missingMessage:'请输入数据'" />
			</p> 
			<p>
				备注:<input name="remark" id="gremark" class="f1 easyui-textbox"
					data-options="required:true,missingMessage:'请输入数据'" />
			</p>
			<div style="padding: 5px; text-align: center;">
				<a href="#" class="easyui-linkbutton" icon="icon-ok"
					onclick="addGoodType()">确认</a> 
					<a href="#" class="easyui-linkbutton"
					icon="icon-cancel" onclick="clearForm()">取消</a>
			</div>
		</form>
	</div>
	<!-- 修改数据框 -->
	 <div class="easyui-window" closed="true" id="updateGoodType" title="信息修改"
		 data-options="modal:true">
		<form id="fm" method="post" style="text-align: center">
			<p>
				货物id:<input name="id" id="id" class="f1 easyui-textbox"	readonly="true"
					data-options="required:true,missingMessage:'该数据不能修改'" />
			</p>
			<p>
				货物名称:<input name="name" id="name" class="f1 easyui-textbox"	
					data-options="required:true,missingMessage:'请输入数据'" />
			</p> 
			<p>
				备注:<input name="remark" id="remark" class="f1 easyui-textbox"
					data-options="required:true,missingMessage:'请输入数据'" />
			</p>
			<div style="padding: 5px; text-align: center;">
				<a href="#" class="easyui-linkbutton" icon="icon-ok"
					onclick="updateGoodType()">确认</a> 
					<a href="#" class="easyui-linkbutton"
					icon="icon-cancel" onclick="clearForm()">取消</a>
			</div>
		</form>
	</div>
</body>
</html>